package swt_1;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;

import swing2swt.layout.BoxLayout;

public class MainWin {

	protected Shell shlA;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			MainWin window = new MainWin();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shlA.open();
		shlA.layout();
		while (!shlA.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shlA = new Shell();
		shlA.setSize(450, 300);
		shlA.setText("a");
		shlA.setLayout(null);
		
		Menu menu = new Menu(shlA, SWT.BAR);
		shlA.setMenuBar(menu);
		
		MenuItem mntmNewSubmenu = new MenuItem(menu, SWT.CASCADE);
		mntmNewSubmenu.setText("File");
		
		Menu menu_1 = new Menu(mntmNewSubmenu);
		mntmNewSubmenu.setMenu(menu_1);
		
		MenuItem mntmNew = new MenuItem(menu_1, SWT.CASCADE);
		mntmNew.setText("New");
		
		Menu menu_2 = new Menu(mntmNew);
		mntmNew.setMenu(menu_2);
		
		MenuItem mntmJavaProject = new MenuItem(menu_2, SWT.NONE);
		mntmJavaProject.setText("Java Project");
		
		MenuItem mntmOpenFile = new MenuItem(menu_1, SWT.NONE);
		mntmOpenFile.setText("Open File");
		
		MenuItem menuItem = new MenuItem(menu_1, SWT.NONE);
		menuItem.setText("个人信息");

		///////////////////////////////////////////////
		// addSelectionListener 	添加选择事件监听器
		// Selection : 鼠标点击按钮 下拉框选择
		// Listener	 : 监听器
		// 时间监听器经常写成 : 匿名类方式
		mntmJavaProject.addSelectionListener(new SelectionAdapter(){

			@Override
			public void widgetSelected(SelectionEvent e) {
				// 点击菜单项, 触发的事件函数
				MessageBox mbox = new MessageBox(shlA);
				mbox.setText("系统提示");
				mbox.setMessage("这是一个信息框");
				mbox.open();
			}
			
		});
		
		menuItem.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				// SWT.NONE 无样式 ==> 默认样式
				MyDialog dialog = new MyDialog(shlA,SWT.NONE);
				dialog.open();
			}
			
		});
		
	}
}
